function isFn(fn) {
    return typeof fn === 'function'
}
// Modal封装
function alert(content, title, showCancel, canText, confirmText, success, cancelFn) {
    if (typeof title == 'function') {
        success = title
        title = ''
    }
    if (typeof showCancel == 'function') {
        cancelFn = showCancel
        showCancel = ''
    }

    wx.showModal({
        content: content || '',
        title: title || '',
        showCancel: showCancel || false,
        cancelText: canText || '取消',
        confirmText: confirmText || '确定',
        confirmColor: '#576B95',
        success: function (res) {
            if (res.confirm) {
                isFn(success) && success(res)
            } else {
                isFn(cancelFn) && cancelFn()
            }
        }
    })
}

// loading
function loading(title) {
    wx.showToast({
        title: title || '加载中...',
        icon: 'loading',
        duration: 200000,
        mask: true
    })
}

function showToast(title, icon, duration, success) {
    wx.showToast({
        title: title || '加载中...',
        icon: icon || 'loading',
        duration: duration || 1500,
        success: success || null,
        mask: true
    })
}
function hide() {
    wx.hideToast()
}

module.exports = {
    alert,
    loading,
    hide,
    showToast
}
